package cn.blackjuly.cadmin.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import cn.blackjuly.cadmin.constant.WebAppConstant;
import cn.blackjuly.cadmin.util.DateUtil;
import cn.blackjuly.cadmin.util.ScannerUtil;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;

public class UploadController extends Controller {
	private final int MAX_SIZE = 50 * 1024 * 1024; // 50M
	private final String IMAGE_DIR = "image";// 指定用户训练视频文件上传路径

	public void image() {
		UploadFile file = getFile("file", IMAGE_DIR, MAX_SIZE, "utf-8");
		JSONObject json = ScannerUtil.WebImage(file.getUploadPath() + "\\" + file.getFileName());
		renderJson(json.toMap());
	}
	
    public void imagefile() {
		Map<String, Object> result = new HashMap<>();
		String uploadPath = IMAGE_DIR + File.separator + DateUtil.now("yyyyMMdd");
		UploadFile file = getFile("file", uploadPath, MAX_SIZE, "utf-8");
		String fileUploadPath = File.separator + WebAppConstant.BASE_UPLOAD_PATH + File.separator +
				uploadPath + File.separator + file.getFileName();
		result.put("url", fileUploadPath);
		result.put("message", "上传成功");
		renderJson(result);
    }
}